import { Loader }  from "andy-ui";

export default function () {
    Loader.loadScript("https://cdn.bootcss.com/FileSaver.js/2014-11-29/FileSaver.min.js");

    class AppDownload extends window.AUI.app.BaseComponent {
        constructor(name) {
            super(name);
            this.methods = {
                setLink(name, file) {
                    this.name = name;
                    this.file = file;
                },
                handleClick() {
                    var self = this;
                    saveAs(self.file, self.name);
                }
            }
        }
        _template() {
            var self = this;
            return `<div class="${self._name}"  style="cursor: pointer;" @click="handleClick">
<div class="aui-color-info">{{name}}</div>
    </div>`;        
        }
        _data() {
            var ret = {};
            ret.name = "";
            ret.file = "";
            return ret;
        }
    }
    
    window.AUICustomComponents.define("app-download", AppDownload); 
}